package compile.fonts {
	import flash.display.Sprite;
	import flash.text.Font;	

	public class AFont extends Sprite 
	{
		protected function get fonts():Array{
			throw(new Error("ASelfAssigningFont::fonts need to be implemented by subclasses"));
		}
		
		public function get fontName():String{
			throw(new Error("ASelfAssigningFont::name need to be implemented by subclasses"));
		}
			
		/**
		 * @throws Error of given font is already assigned
		 */
		public function register():void{
			if(fontsExists())
				throw(new Error("Font with the name "+fontName+" is already registered"));
			
			var font:Class;
			var fonts:Array = fonts;
			for each(font in fonts)
				Font.registerFont(font);
		}
		
		private function fontsExists():Boolean{
			var fonts:Array = Font.enumerateFonts();
			for each(var font:Font in fonts){
				if(font.fontName==fontName)
					return true;	
			}
			return false;
		}
			
		public function AFont(){
			super();
		}
	}
}
